﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RegisterationCommon.NoticeParents;
using RegisterationCommon.Common;
using System.Data;
using RegisterationCommon.NoticeReceive;

namespace RegisterationSystem.Space_School
{
    public partial class notice_add : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
         //添加
        protected void Button1_Click(object sender, EventArgs e)
        {
            
            NoticeParents np = new NoticeParents();
            np.Title = txtname.Text.Trim();
            np.Status = Convert.ToInt32(ddlstatus.SelectedValue);
            np.Content = txtContent.Text.Trim();
            np.SchId = Convert.ToInt32(Cookies.Get("SchID"));
            np.Recrive = Convert.ToInt32(ddlRecrive.SelectedValue);
            np.RTime = DateTime.Now;
            int a=np.AddNoticePt();
            if (a!=0)
            {
                string where = "SchID=" + Convert.ToInt32(Cookies.Get("SchID")) + " and Status=2 and IsDelete=0";//找到该学校下审核通过的所有学生信息
                DataTable dtst = DBAction.GetDTFromSQL("Select * From Students where "+ where);
                if (dtst.Rows.Count < 1)
                {

                }
                else
                {
                    for (int i = 0; i < dtst.Rows.Count; i++)
                    {
                        NoticeReceive rp = new NoticeReceive();
                        rp.NoticeID =a ;
                        rp.StudentID = Convert.ToInt32(dtst.Rows[i]["ID"].ToString());
                        rp.ReceiveTime = DateTime.Now;
                        rp.SchId = Convert.ToInt32(Cookies.Get("SchID"));
                        rp.Sname = dtst.Rows[i]["TrueName"].ToString();
                        rp.Gname = dtst.Rows[i]["FirstGuardianName"].ToString();
                        rp.Address = dtst.Rows[i]["PermanentAddress"].ToString();
                        rp.Ext1 = "0";//0为未查看公告
                        rp.Ext2 = "";
                        rp.Ext3 = "";
                        rp.Ext4 = "";
                        rp.AddNoticePt();
                    }
                }


                Message.Send(10041);
            }
            else
            {
                Message.Send(10042);
            }
        }
    }
}